package com.xwm93up.basic.linkedhashmap;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description: desc
 * @Author: xwm93up
 * @Since: 2021/11/10 17:09
 */
public class TestOrder {
    public static void main(String[] args) {
        orderHashMap();
        orderLinkedHashMap();
    }

    // 顺序,orderHashMap
    private static void orderHashMap () {
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("化学","93");
        hashMap.put("数学","98");
        hashMap.put("生物","92");
        hashMap.put("英语","97");
        hashMap.put("物理","94");
        hashMap.put("历史","96");
        hashMap.put("语文","99");
        hashMap.put("地理","95");
        for (Map.Entry entry : hashMap.entrySet())
        {
            System.out.println(entry.getKey().toString() + ":" + entry.getValue().toString());
        }
        System.out.println("================================================================");
    }

    // 顺序,orderLinkedHashMap
    private static void orderLinkedHashMap () {
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put("化学","93");
        linkedHashMap.put("数学","98");
        linkedHashMap.put("生物","92");
        linkedHashMap.put("英语","97");
        linkedHashMap.put("物理","94");
        linkedHashMap.put("历史","96");
        linkedHashMap.put("语文","99");
        linkedHashMap.put("地理","95");
        for (Map.Entry entry : linkedHashMap.entrySet())
        {
            System.out.println(entry.getKey().toString() + ":" + entry.getValue().toString());
        }
    }
}
